from django.shortcuts import HttpResponse
from django.http import JsonResponse
from django.core.serializers.json import json


def success_result_json(data=None, msg='成功', code=200):
    result = {
        "success": True,
        "code": code,
        "msg": msg,
        "data": data
    }
    return JsonResponse(result)


def fail_result_json(data=None, msg='请求失败', code=500):
    result = {
        "success": False,
        "code": code,
        "msg": msg,
        "data": data
    }
    return JsonResponse(result)


# def fail_result_json(data, msg='请求失败', code=500):
#     result = {
#         "success": False,
#         "code": code,
#         "msg": msg,
#         "data": data
#     }
#     return HttpResponse(json.dumps(result, ensure_ascii=False), content_type="application/json; charset=utf-8")
